package com.learn.spring.mybatis.core;

import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

public class MyImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {
    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        // 将UserMapper注册到Spring容器中
        RootBeanDefinition beanDefinition = new RootBeanDefinition(MyFactoryBean.class);
        beanDefinition.getConstructorArgumentValues()
                .addGenericArgumentValue("com.learn.spring.mybatis.mapper.UserMapper");
        registry.registerBeanDefinition("userMapper", beanDefinition);

        RootBeanDefinition beanDefinition1 = new RootBeanDefinition(MyFactoryBean.class);
        beanDefinition1.getConstructorArgumentValues()
                .addGenericArgumentValue("com.learn.spring.mybatis.mapper.AccountMapper");
        registry.registerBeanDefinition("accountMapper", beanDefinition1);

    }
}
